package com.baizhi.baseapp.widget;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.Color;
import android.os.Build;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

import com.baizhi.baseapp.R;
import com.baizhi.baseapp.util.DeviceUtils;

import java.lang.ref.WeakReference;

public class WToast {
    private static Toast mToast;
    private static Context mContext;

    public static void init(Context context) {
        mContext = context;
    }

    public static void showToast(String text) {
        showToast(text, Toast.LENGTH_LONG);
    }

    /**
     * 显示一个toast提示
     *
     * @param text     toast字符串
     * @param duration toast显示时间
     */
    public static void showToast(String text, int duration) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            Toast.makeText(mContext, text, duration).show();
        } else {
            if (mToast == null) {
                mToast = Toast.makeText(mContext, text, duration);
            } else {
                mToast.setText(text);
                mToast.setDuration(duration);
            }
            mToast.show();
        }
    }
}
